package com.mtiiot.fstcpserver.log;

import com.mtiiot.fscore.bean.MetadataInfo;
import com.mtiiot.fscore.bean.elasticsearch.metadata.LogMetadata;
import com.mtiiot.fscore.inter1.LogService1;
import com.mtiiot.fscore.utils.LogLevel;
import com.mtiiot.fscore.utils.RequestType;
import com.mtiiot.fstcpserver.base.BaseService;
import com.mtiiot.fstcpserver.utils.Constants;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;


/**
 * Created by Administrator on 16-6-16.
 */
public class LogServiceImpl1 extends BaseService implements LogService1 {
    private static final Logger logger = LogManager.getLogger(LogServiceImpl1.class);

    /**
     * @param mi 元数据类
     * @param logLevel     日志级别枚举类
     * @param keyValue     关键字搜索值
     * @param message      日志消息
     * @return boolean if true success;else false failure!
     */
    @Override
    public boolean sendLog(MetadataInfo mi, LogLevel logLevel, String keyValue, String message) {
        try{
            //日志数据入队列
            checkMetadata(mi);//验证元数据
            LogMetadata md=new LogMetadata();
            setMetadataBeanData(mi,md,RequestType.INSERT.getName(),message);
            md.setKeyValue(keyValue);
            md.setLogLevel(logLevel.getName());
            md.setMessage(message);
            metadataInQueue(Constants.TOPIC_METADATAINFO,Constants.TYPE_METADATA_LOG,md);
            return true;
        }catch(Exception ex){
            //异常信息 元数据入reids队列
            handleException(Constants.MODULE_LOG,"LogServiceImpl1","sendLog",ex,logger);
            return false;
        }
    }
}
